package cn.ustb.controller;

import cn.ustb.entity.StudentGrade;
import cn.ustb.service.StudentGradeService;
import cn.ustb.serviceImpl.StudentGradeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author yuyan
 */
@WebServlet("/updateStudentGradeServlet")
public class updateStudentGradeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    StudentGradeService studentGradeService=new StudentGradeServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        HttpSession session = request.getSession();
        String yearTerm = request.getParameter("yearTerm");
        String studentId = request.getParameter("studentId");
        String studentName = request.getParameter("studentName");
        String courseId = request.getParameter("courseId");
        String courseName = request.getParameter("courseName");
        String score = request.getParameter("score");
        String gradePoint = request.getParameter("gradePoint");
        String credit = request.getParameter("credit");
        String courseClass = request.getParameter("courseClass");
        String examWay = request.getParameter("examWay");
        String studyWay = request.getParameter("studyWay");
        String gradeWay = request.getParameter("gradeWay");
        String effectivity = request.getParameter("effectivity");
        String remarks = request.getParameter("remarks");

        StudentGrade studentGrade =  new StudentGrade();
        studentGrade.setYearTerm(yearTerm);
        studentGrade.setStudentId(studentId);
        studentGrade.setStudentName(studentName);
        studentGrade.setCourseId(courseId);
        studentGrade.setCourseName(courseName);
        studentGrade.setScore(score);
        studentGrade.setGradePoint(gradePoint);
        studentGrade.setCredit(credit);
        studentGrade.setCourseClass(courseClass);
        studentGrade.setExamWay(examWay);
        studentGrade.setStudyWay(studyWay);
        studentGrade.setGradeWay(gradeWay);
        studentGrade.setEffectivity(effectivity);
        studentGrade.setRemarks(remarks);
        studentGradeService.update(studentGrade);

        String message = "修改成功";
        session.setAttribute("message", message);
        response.sendRedirect(request.getContextPath() + "/updateStudentGrade.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}